const Controller = require('../core/base_controller');

const _ = require('lodash');
const path = require('path')
const fs = require('mz/fs');

class AppController extends Controller {
  async index() {
    const { app, app: { dd } } = this;


    let ret = await this.service.user.getChildUser()

    this.ctx.body = 'hi, egg';
    console.log('请求');
  }

  // 同步钉钉用户
  async asyncUser() {
    const { service: { dd } } = this
    let ret = await dd.getUser()

    this.success(ret);
  }

  //升级数据库
  async upgrade() {
    let { app } = this
    await app.model.sync({ alter: true });
    this.success()
  }

  // 初始化系统数据
  async init() {
    const { service: { dbInit } } = this;
    await dbInit.initRole();
    await dbInit.initPower();
    await dbInit.initDict();
    await dbInit.initCompany();
    this.success();
  }

  //测试3
  async test() {
    const apiClass = require('../lib/dingtalk')
    const api = apiClass(this.app)
    let ret = await api.rest.sendMessage({
      msgtype: 'text',
      agent_id: 131424918,
      userid_list: '04313145011220506',
      to_all_user: false,
      msgcontent: JSON.stringify({
        "content": "测试数据 张三的请假申请"
      })
    })
    this.success(ret)
  }

}
module.exports = AppController;
